/*
 * JBoss, Home of Professional Open Source
 * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
 * contributors by the @authors tag. See the copyright.txt in the
 * distribution for a full listing of individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package br.com.fiap.vendas.ejb;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import br.com.fiap.vendas.business.exception.ServiceException;
import br.com.fiap.vendas.business.service.interfaces.ProdutoService;
import br.com.fiap.vendas.business.service.interfaces.UsuarioService;
import br.com.fiap.vendas.business.vo.UsuarioVO;
import br.com.fiap.vendas.common.locator.ContextEnvironment;
import br.com.fiap.vendas.common.locator.ServiceLocator;

import java.util.Hashtable;

/**
 * A sample program which acts a remote client for a EJB deployed on AS7 server. This program shows how to lookup stateful and
 * stateless beans via JNDI and then invoke on them
 * 
 * @author Jaikiran Pai
 */
public class EjbTest {

    public static void main(String[] args) throws Exception {
        // Invoke a stateless bean
        invokeStatelessBean();

      
    }

    /**
     * Looks up a stateless bean and invokes on it
     * 
     * @throws NamingException
     * @throws ServiceException 
     */
    private static void invokeStatelessBean() throws NamingException {
        // Let's lookup the remote stateless calculator
        final UsuarioService statelessRemoteCalculator = lookupRemoteStatelessCalculator();
        	
        try {
			statelessRemoteCalculator.inserirUsuario(new UsuarioVO("teste", "teste", "teste", "teste", "teste", "tetse"));
		} catch (ServiceException e) {
		
			e.printStackTrace();
		}catch (Exception e) {
			e.printStackTrace();
		}
       

        System.out.println("Obtained a remote stateless calculator for invocation");
        
    }

    private static UsuarioService lookupRemoteStatelessCalculator() throws NamingException {

    	ProdutoService prod = (ProdutoService) ServiceLocator.getInstance().lookup(ProdutoService.JNDI_NAME);
    	prod.listarTodosProdutos();
        return (UsuarioService) ServiceLocator.getInstance().lookup(UsuarioService.JNDI_NAME
);
    }

    }